package net.udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class ReceiverThread extends Thread
{
	DatagramSocket socket;
	private boolean stopped = false;
	public ReceiverThread(DatagramSocket ds)
	{
		this.socket = ds;
	}
	public void halt()
	{
		this.stopped = true;
	}
	@Override
	public void run()
	{
		byte[] buffer = new byte[65507];
		while(true)
		{
			if(stopped)
			{
				return;
			}
			DatagramPacket dp = new DatagramPacket(buffer, buffer.length);
			try
			{
				socket.receive(dp);
				String s = new String(dp.getData(),0,dp.getLength());
				System.out.println(s);
				Thread.yield();
			}
			catch (Exception e)
			{
			}
		}
		
	}
}
